package com.steel.yfmall.cloud.assistant.goods.impl;

import com.steel.yfmall.cloud.assistant.dto.para.goods.ParaProductSaleCompanyInfoBean;
import com.steel.yfmall.cloud.assistant.goods.ProductSaleCompanyInfoBeanService;
import com.steel.yfmall.cloud.assistant.goods.mapper.ProductSaleCompanyInfoBeanMapper;
import com.steel.yfmall.cloud.assistant.po.goods.ProductSaleCompanyInfoBean;
import com.steel.yfmall.cloud.assistant.po.goods.ProductSaleCompanyInfoBeanExample;
import com.steel.yfmall.cloud.components.utils.utils.MobileBaseBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: ProductSaleCompanyInfoBeanServiceImpl
 * @Package com.steel.yfmall.cloud.assistant.goods.impl
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/1/21 19:54
 */
@Slf4j
@Service
public class ProductSaleCompanyInfoBeanServiceImpl implements ProductSaleCompanyInfoBeanService {

    @Resource
    private ProductSaleCompanyInfoBeanMapper productSaleCompanyInfoBeanMapper;

    /**
     * 查询条件拼接
     */
    private void getSearchData(ProductSaleCompanyInfoBeanExample.Criteria criteria, ParaProductSaleCompanyInfoBean paraBean) {
        if (criteria == null || paraBean == null) {
            return;
        }

        if (StringUtils.isNotBlank(paraBean.getSaleCompanyCode())) {
            criteria.andSaleCompanyCodeEqualTo(paraBean.getSaleCompanyCode());
        }

        if (!CollectionUtils.isEmpty(paraBean.getSaleCompanyCodes())) {
            criteria.andSaleCompanyCodeIn(paraBean.getSaleCompanyCodes());
        }

        if (StringUtils.isNotBlank(paraBean.getSaleCompanyName())) {
            criteria.andSaleCompanyNameEqualTo(paraBean.getSaleCompanyName());
        }

        if (StringUtils.isNotBlank(paraBean.getSaleCompanyNameLike())) {
            criteria.andSaleCompanyNameLike("%" + paraBean.getSaleCompanyNameLike() + "%");
        }

        if (paraBean.getStatus() != null) {
            criteria.andStatusEqualTo(paraBean.getStatus());
        }
    }

    /**
     * 获取销售公司集合
     * @Title: getProductSaleCompanyInfoBeanByList
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return java.util.List<com.steel.yfmall.cloud.assistant.po.goods.ProductSaleCompanyInfoBean>    返回类型
     * @author yuchaohua
     * @date 2021/1/21 20:01
     */
    @Override
    public List<ProductSaleCompanyInfoBean> getProductSaleCompanyInfoBeanByList(ParaProductSaleCompanyInfoBean paraBean) {
        ProductSaleCompanyInfoBeanExample example = new ProductSaleCompanyInfoBeanExample();
        ProductSaleCompanyInfoBeanExample.Criteria criteria = example.createCriteria();
        getSearchData(criteria, paraBean);
        return productSaleCompanyInfoBeanMapper.selectByExample(example);
    }

    /**
     * 获取单个销售公司信息
     * @Title: getProductSaleCompanyInfoBeanByPara
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return com.steel.yfmall.cloud.assistant.po.goods.ProductSaleCompanyInfoBean    返回类型
     * @author yuchaohua
     * @date 2021/1/21 20:01
     */
    @Override
    public ProductSaleCompanyInfoBean getProductSaleCompanyInfoBeanByPara(ParaProductSaleCompanyInfoBean paraBean) {
        ProductSaleCompanyInfoBeanExample example = new ProductSaleCompanyInfoBeanExample();
        ProductSaleCompanyInfoBeanExample.Criteria criteria = example.createCriteria();
        getSearchData(criteria, paraBean);
        return productSaleCompanyInfoBeanMapper.selectOneByExampleSelective(example);
    }
}
